﻿using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ApplicationServices.Core;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace haimian
{
    internal class CalloutPaletteSet : PaletteSet
    {
        // static field
        static bool wasVisible;

        /// <summary>
        /// Creates a new instance of CustomPaletteSet.
        /// </summary>
        public CalloutPaletteSet()
            : base("SB海绵设施批量统计", "HUA", new Guid("{6A1DEB26-886E-471E-B00F-771FFE573625}"))
        {
            Style =
                PaletteSetStyles.ShowAutoHideButton |
                PaletteSetStyles.ShowCloseButton |
                PaletteSetStyles.ShowPropertiesMenu;
            MinimumSize = new System.Drawing.Size(250, 150);
            AddVisual("BiaoZhu", new CalloutPattlePanel());

            // automatically hide the palette while none document is active (no document state)
            var docs = Application.DocumentManager;
            docs.DocumentBecameCurrent += (s, e) =>
                Visible = e.Document == null ? false : wasVisible;
            docs.DocumentCreated += (s, e) =>
                Visible = wasVisible;
            docs.DocumentToBeDeactivated += (s, e) =>
                wasVisible = Visible;
            docs.DocumentToBeDestroyed += (s, e) =>
            {
                wasVisible = Visible;
                if (docs.Count == 1)
                    Visible = false;
            };
        }
    }
}
